package cn.edu.zut.curriculum.service.impl;

import cn.edu.zut.curriculum.entity.User;
import cn.edu.zut.curriculum.mapper.CommodityMapper;
import cn.edu.zut.curriculum.mapper.UserMapper;
import cn.edu.zut.curriculum.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Userserviceimpl implements IUserService {
    @Autowired
    UserMapper userMapper;
    CommodityMapper commodityMapper;
    @Override
    public User register(User user){
        User u1=userMapper.queryByPhone(user.getPhone());
        if(u1!= null) {
            user.setMessage("手机号已注册");
            return user;
        }
       /* User u2=userMapper.queryByEmail(user.getEmail());
        if(u2!= null) {
            user.setMessage("邮箱已注册");
            return user;
        }
         */

        if(userMapper.save(user)==1){
            return user;
        }
        user.setMessage("未知异常，请重新注册");
        return user;
    }

    @Override
    public User login(String account,String password){
        User user =userMapper.queryByAccount(account,account);
        if(user!=null&&user.getPassword().equals(password)){
            return user;
        }
        return null;
    }

    @Override
    public User select(long id){
        User user =userMapper.queryByIdUser(id);
               return user;
    }
    @Override
    //管理员禁言
    public int update(long id){
        int i=userMapper.updateUser(id);
        return i;
    }

    @Override
    public int update2(User user,long id){
        int i=userMapper.updateUser2(user,id);
        return i;
    }

}

